* Analyze macropartisanship data for structural breaks using Xtb
* 12-1-22

* import .csv file
clear
import delimited "/Users/dongreen/Dropbox/macropartisanship (1)/01_data/macro_data.csv"

* format date --> quarterly
gen qdate = quarterly(date, "YQ")
format qdate %tq

* declare time-series format
tsset qdate, quarterly

* fill in transition dummies that were not in the dataset
gen clinton1 = 0
replace clinton1 = 1 if date == "1993q1"

gen reagan1 = 0
replace reagan1 = 1 if date == "1981q1"

* rescale ICS so that we have more significant digits
replace ics = ics/100
replace party_ics = party_ics/100

* create a sign-flipping party indicator
gen party_ind = (dem_pres *2)-1

/*
Mode adjustment

. reg macropartisanship macro_landline_only macro_two_modes if year > 1983 & year < 1989

      Source |       SS           df       MS      Number of obs   =        20
-------------+----------------------------------   F(2, 17)        =      1.17
       Model |  .001204099         2   .00060205   Prob > F        =    0.3355
    Residual |  .008782495        17  .000516617   R-squared       =    0.1206
-------------+----------------------------------   Adj R-squared   =    0.0171
       Total |  .009986594        19   .00052561   Root MSE        =    .02273

-------------------------------------------------------------------------------------
  macropartisanship |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
--------------------+----------------------------------------------------------------
macro_landline_only |  -.0388495   .0262454    -1.48   0.157    -.0942225    .0165235
    macro_two_modes |  -.0144603   .0143002    -1.01   0.326     -.044631    .0157104
              _cons |   .5589388   .0131227    42.59   0.000     .5312523    .5866253
-------------------------------------------------------------------------------------

*/
* remove mode effects
gen macropid_adj = macropartisanship - macro_landline_only * -.0388495 - macro_two_modes *  -.0144603

* create a president counter*party_ics
gen pres_count=eisenhower+2*kennedy+3*johnson+4*nixon+5*ford+6*carter+7*reagan+8*hwbush+9*clinton+10*wbush+11*obama+12*trump+13*biden
label define preslabel 1 "IKE" 2 "JFK" 3 "LBJ" 4 "RMN" 5 "GRF" 6 "JEC" 7 "RWR" 8 "GHWB" 9 "WJC" 10 "GWB" 11 "BO" 12 "DJT" 13 "JRB"
label values pres_count preslabel

* create a modern period indicator
gen modern = 0
replace modern = 1 if year > 1987


****************************************************************
*search for structural breaks using three step method in xtbreak: Table 3 "xtb" columns
****************************************************************
* includes both ICS and approval
xtbreak test macropid_adj L1.macropid_adj party_approval party_ics party_ind
xtbreak test macropid_adj L1.macropid_adj party_approval party_ics party_ind,h(1) breaks(5)
xtbreak estimate macropid_adj L1.macropid_adj party_approval party_ics party_ind, breaks(5) 

* check whether the results differ if one just uses ICS (only the first break is sig)
xtbreak test     macropid_adj L1.macropid_adj  party_ics party_ind
xtbreak test     macropid_adj L1.macropid_adj  party_ics party_ind,h(1) breaks(5)
xtbreak estimate macropid_adj L1.macropid_adj  party_ics party_ind, breaks(5) 

xtbreak test     macropid_adj L1.macropid_adj  party_ics party_ind,h(1) breaks(4)
xtbreak estimate macropid_adj L1.macropid_adj  party_ics party_ind, breaks(4) 

xtbreak test     macropid_adj L1.macropid_adj  party_ics party_ind,h(1) breaks(3)
xtbreak estimate macropid_adj L1.macropid_adj  party_ics party_ind, breaks(3) 

xtbreak test     macropid_adj L1.macropid_adj  party_ics party_ind,h(1) breaks(2)
xtbreak estimate macropid_adj L1.macropid_adj  party_ics party_ind, breaks(2) 

xtbreak test     macropid_adj L1.macropid_adj  party_ics party_ind,h(1) breaks(1)
xtbreak estimate macropid_adj L1.macropid_adj  party_ics party_ind, breaks(1) 

* check whether the results differ if one just uses approval (same breaks as first specification)
xtbreak test     macropid_adj L1.macropid_adj  party_approval party_ind
xtbreak test     macropid_adj L1.macropid_adj  party_approval party_ind,h(1) breaks(5)
xtbreak estimate macropid_adj L1.macropid_adj  party_approval party_ind, breaks(5) 

xtbreak test     macropid_adj L1.macropid_adj  party_approval party_ind,h(1) breaks(4)
xtbreak estimate macropid_adj L1.macropid_adj  party_approval party_ind, breaks(4) 

xtbreak test     macropid_adj L1.macropid_adj  party_approval party_ind,h(1) breaks(3)
xtbreak estimate macropid_adj L1.macropid_adj  party_approval party_ind, breaks(3) 

xtbreak test     macropid_adj L1.macropid_adj  party_approval party_ind,h(1) breaks(2)
xtbreak estimate macropid_adj L1.macropid_adj  party_approval party_ind, breaks(2) 

xtbreak test     macropid_adj L1.macropid_adj  party_approval party_ind,h(1) breaks(1)
xtbreak estimate macropid_adj L1.macropid_adj  party_approval party_ind, breaks(1) 


